package com.xsmart.oa.api;

import com.xsmart.common.entity.RequestBean;
import com.xsmart.common.entity.ResponseBean;
import com.xsmart.oa.services.UserAddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * 用户常用地址
 *
 * @author 郭建德
 */
@RestController
@RequestMapping("/api")
public class UserAddressController {
    @Autowired
    UserAddressService userAddressService;

    @PostMapping(value = "/v1/UserAddressService/getAreaList")
    public ResponseBean getAreaList(@ModelAttribute RequestBean requestBean, HttpServletRequest request) {
        return userAddressService.getAreaList(requestBean);
    }

    @PostMapping(value = "/v1/UserAddressService/queryUserAddress")
    public ResponseBean queryUserAddress(@ModelAttribute RequestBean requestBean, HttpServletRequest request) {
        return userAddressService.queryUserAddress(requestBean);
    }

    @PostMapping(value = "/v1/UserAddressService/querydefaultAddress")
    public ResponseBean querydefaultAddress(@ModelAttribute RequestBean requestBean, HttpServletRequest request) {
        return userAddressService.querydefaultAddress(requestBean);
    }

    @PostMapping(value = "/v1/UserAddressService/setDefault")
    public ResponseBean setDefault(@ModelAttribute RequestBean requestBean, HttpServletRequest request) {
        return userAddressService.setDefault(requestBean);
    }

    /**
     * 添加地址
     *
     * @param requestBean adds: 详细地址
     *                    city: 地市
     *                    code: 编码
     *                    quyu: 区县
     *                    receiver: 收货人
     *                    sheng: 省
     *                    tel: 电话
     *                    user_id: 用户id
     * @param request 请求对象
     * @return 添加结果
     */
    @PostMapping(value = "/v1/UserAddressService/addUserAddress")
    public ResponseBean addUserAddress(@ModelAttribute RequestBean requestBean, HttpServletRequest request) {
        return userAddressService.addUserAddress(requestBean);
    }

    @PostMapping(value = "/v1/UserAddressService/modUserAddress")
    public ResponseBean modUserAddress(@ModelAttribute RequestBean requestBean, HttpServletRequest request) {
        return userAddressService.modUserAddress(requestBean);
    }

    @PostMapping(value = "/v1/UserAddressService/delUserAddress")
    public ResponseBean delUserAddress(@ModelAttribute RequestBean requestBean, HttpServletRequest request) {
        return userAddressService.delUserAddress(requestBean);
    }
}
